package com.ljf.framework.Async;

import com.ljf.framework.LjfManager;
import com.ljf.framework.context.LjfContext;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 说明：异步任务事件
 *
 * @Auther: lijinfeng
 * @Date: 2024/8/1
 */
public abstract class AsyncEvent<T> {

    private ConcurrentHashMap map = new ConcurrentHashMap();

    public abstract T run();

    public T runPrepare(){
        // 设置上下文
//        LjfManager.getLjfContext().syncContext(map.get("ljfContextObject"));
        LjfManager.getLjfContextOrSecond().syncContext(map.get("ljfContextObject"));
        return run();
    };

    public void setLjfContext(LjfContext context){
        if (context == null)
            return;
        map.put("ljfContextObject",context.getSyncObject());
    };
}
